package com.bxkc.generator.response;



/**
 * 通用返回对象
 */
public class CommonResult<T> {
    private boolean sussess;
    private String code;
    private String message;
    private T data;



    private CommonResult(boolean sussess, String code, String message, T data) {
        this.sussess = sussess;
        this.code = code;
        this.message = message;
        this.data = data;
    }

    /**
     * 成功返回结果
     *
     */
    public static <T> CommonResult<T> success() {
        return new CommonResult<T>(true, ResultEnum.SUCCESS.getCode(), ResultEnum.SUCCESS.getMessage(), null);
    }

    /**
     * 成功返回结果
     *
     * @param data 获取的数据
     */
    public static <T> CommonResult<T> success(T data) {
        return new CommonResult<T>(true, ResultEnum.SUCCESS.getCode(), ResultEnum.SUCCESS.getMessage(), data);
    }


    /**
     * 失败返回结果
     * @param errorCode 错误码
     */
    public static <T> CommonResult<T> failed(ResultInterface errorCode) {
        return new CommonResult<T>(false,errorCode.getCode(), errorCode.getMessage(), null);
    }


    /**
     * 失败返回结果
     */
    public static <T> CommonResult<T> failed() {
        return failed(ResultEnum.FAILED);
    }






    public boolean isSussess() {
        return sussess;
    }

    public void setSussess(boolean sussess) {
        this.sussess = sussess;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
